import { isJSON } from '@/utils/type'

export function parseStatus(dict, type, code, separator = ',') {
  let _code
  if (isJSON(code)) {
    _code = JSON.parse(code)
  } else {
    _code = code
  }
  if (Array.isArray(_code)) {
    let text = []
    _code.forEach(code => {
      text.push(dict[type].filter(status => status.value == code).map(status => status.label).join(separator))
    })
    return text.join(separator)
  } else {
    const text = dict[type].filter(status => status.value == code).map(status => status.label).join(separator)
    return text ? text : '-'
  }
}

// 城市code轮换为城市名称
export function parseCityCode(cityData, code) {
  const city =  cityData.filter(city => city.code == code)[0]
  return city ? city.name : ''
}